import { Service } from "cl-admin";
import BaseService from "@/service/base";
import qs from "qs";
@Service("Spread")
class Spread extends BaseService {
	// 查询城市
	getbizcity(params) {
		return this.$get("/getbizcity", { params });
	}

	// 查询城市，在新增客户，预约页面中使用
	newGetbizcity(params) {
		return this.$get("/getbizcity", { params });
	}

	// 添加城市
	addmanagecity(params) {
		return this.$post("/addmanagecity", params);
	}
	// 修改城市
	editmanagecity(params) {
		return this.$post("/editmanagecity", params);
	}
	// 删除城市
	delmanagecity(params) {
		return this.$post("/delmanagecity", params);
	}
	// 获取城市产出比1
	listcityoutput({ date, ...args }) {
		let params = {
			...args
		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		return this.$post("/listcityoutput", params);
	}
	// 获取城市产出比2 -- 平台产出比
	listcityoutputratio({ date, bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id.join()

		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		return this.$post("/listcityoutputratio", params);
	}
	// 获取城市产出比3
	listcityoutputratio2({ bra_id = [], ...args }) {
		let params = {
			bra_id: bra_id.join(),
			...args
		}
		return this.$post("/listcityoutputratio2", params);
	}
	// 获取组员产出比
	listuseroutputratio({ bra_id = [], ...args }) {
		let params = {
			bra_id: bra_id.join(),
			...args
		}
		return this.$post("/listuseroutputratio", params);
	}
	// 获取部门
	getmanagedept(params) {
		return this.$get("/getmanagedept", { params });
	}
	// 查询月推广目标
	listpromotionplan({ size, dept_ids, bra_id = [], ...args }) {
		let params = {
			...args,
			dept_id: dept_ids.join(),
			bra_id: bra_id.join(),
			page_size: size
		};
		return this.$post("/listpromotionplan", params).then(res => {
			return {
				list: res.list,
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}
	// 添加月推广目标
	addpromotionplan(params) {
		return this.$post("/addpromotionplan", qs.stringify(params));
	}
	// 删除月推广目标
	delpromotionplan(params) {
		return this.$post("/delpromotionplan", params);
	}
	// 更改月推广目标
	editpromotionplan(params) {
		return this.$post("/editpromotionplan", qs.stringify(params));
	}
	// 获取部门组员
	getmanagedeptuser(params) {
		return this.$get("/getmanagedeptuser", { params });
	}

	// 添加组员推广目标
	addpersonpromotionplan(params) {
		return this.$post("/addpersonpromotionplan", qs.stringify(params));
	}
	// 获取组员目标列表
	listpersonpromotionplan(params) {
		return this.$post("/listpersonpromotionplan", params);
	}
	// 更新组员推广目标
	editpersonpromotionplan(params) {
		return this.$post("/editpersonpromotionplan", params);
	}
	// 删除组员推广目标
	delpersonpromotionplan(params) {
		return this.$post("/delpersonpromotionplan", params);
	}

	// 本月完成度
	listmonthpromotionplan({ date, bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id.join()
		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		return this.$get("/listmonthpromotionplan", { params });
	}
	// 本月消耗
	listmonthchanneltrace({ date, bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id?.join?.()
		};
		if (date?.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		return this.$get("/listmonthchanneltrace", { params });
	}
	// 获取日跟踪列表
	daytracelist(params) {
		return this.$post("/daytracelist", params);
	}
	// 添加日跟踪列表
	adddaytrace(params) {
		return this.$post("/adddaytrace", params);
	}
	// 删除日跟踪列表
	deldaytrace(params) {
		return this.$post("/deldaytrace", params);
	}
	// 日跟踪明细
	daytracedetail(params) {
		return this.$post("/daytracedetail", params);
	}
	// 下载辅助数据
	auxiliarydata(params) {
		return this.$get("/auxiliarydata", { params });
	}
	// 下载日跟踪数据模板
	promotiontracefiletemplate(params) {
		return this.$post("/promotiontracefiletemplate", params);
	}

	// 推广目标报表本月消耗 以平台为单位进行汇总--汇总按钮-售前汇总
	listmonthchanneltraceCollect({ size, date = [], bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id?.join?.()
		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		if (params.type == 2) {
			params.page_size = size;
		}
		console.log(params);
		return this.$get("/listmonthchanneltraceCollect", { params }).then(res => {
			if (params.type == 1) {
				return res;
			}
			return {
				list: res.data,
				pagination: {
					...params,
					size,
					total: res.total
				},

			};
		});
	}

   // 推广目标报表本月消耗 以平台为单位进行汇总--汇总按钮-运营汇总
   listMonthChannelTraceSpread({ size, date = [], bra_id = [], ...args }) {
		let params = {
			...args,
			bra_id: bra_id?.join?.()
		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		// if (params.type == 2) {
		// 	params.page_size = size;
		// }
		console.log(params);
		return this.$get("/listMonthChannelTraceSpread", { params }).then(res => {
			// if (params.type == 1) {
			// 	return res;
			// }

			return {
				list: res.data_list,
				pagination: {
					...params,
					size,
					total: res.total
				},
				data_list: res.data_list,
				data_title: res.data_title,
				data_total: res.data_total,
			};
		});
	}



	// 推广目标报表(本月完成度) -- 按钮
	listmonthpromotionplancheck({ size, ...params }) {
		return this.$get("/listmonthpromotionplancheck", { params });
	}
	// 开关
	spreadOnoff({ date, dept_ids = [], bra_id = [], ...args }) {
		console.log(bra_id);
		let params = {
			dept_id: dept_ids.join(),
			bra_id: bra_id.join(),
			...args
		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		return this.$get("/onoff", { params });
	}
	// 开关详情
	spreadOnoffDetail(params) {
		// let params = {
		// 	dept_id: dept_ids.join(),
		// 	...args
		// };
		// if (date && date.length) {
		// 	params.begin_time = date[0];
		// 	params.end_time = date[1];
		// }
		return this.$get("/onOffDetail", { params }).then(res => {
			return {
				list: res.list,
				pagination: {
					...params,
					total: res.total
				}
			};
		})
	}
	//  推广线索列表-全部
	clueList({ date, size, ...args }) {
		let params = {
			...args,
			size: size
		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		// console.log(params)
		return this.$get("/clueList", { params }).then(res => {
			// console.log(res)
			return {
				list: res.data || res ,
				pagination: {
					...params,
					size,
					total: res.total || res.length
				}
			};
		});
	}

    // 推广线索列表-我领取的线索
	myClue({ date, size, ...args }) {
		let params = {
			...args,
			size: size
		};
		if (date && date.length) {
			params.begin_time = date[0]
			params.end_time = date[1]
		}
		// console.log(params)
		return this.$get("/myClue", { params }).then(res => {
			// console.log(res)
			return {
				list: res.data || res,
				pagination: {
					...params,
					size,
					total: res.total || res.length
				}
			};
		});
	}

	 // 推广线索列表-我上传的线索
	 ownClue({ size,appoint_date, ...args }) {
		let params = {
			...args,
			size: size
		};
		if(appoint_date && appoint_date.length>0){
            params.create_begin = appoint_date[0]
			params.create_end = appoint_date[1]
		}
		console.log(params)
		return this.$get("/ownClue", { params }).then(res => {
			console.log(res)
			return {
				list: res.data || res ,
				pagination: {
					...params,
					size,
					total: res.total || res.length
				}
			};
		});
	}

	//线索报表
	clueReport({ time = [], ...args }) {

		let params = {
			...args
		}
		if (time) {
			params.begin = time[0]
			params.end = time[1]
		}
		return this.$get("/clueReport", { params }).then(res => {
			// console.info("eeeeee", res)
			return {
				data_list: res.data_list,
				data_title: res.data_title,
				pagination: {
					...params,
					total: res.page_data
				},
				data_total:res.data_total
			};
		})
	}

    // 线索跟进记录操作
	followUp(params){
		return this.$post("/followUp", params);
	}

	// 推广线索领取
	getClue(params) {
		return this.$post("/getClue", params);
	}

	// 推广线索修改
	clueEdit(params) {
		return this.$post("/clueEdit", params);
	}

	// 推广线索删除
	clueDel(params) {
		return this.$post("/clueDel", params);
	}

	getMyClue() {
		return this.$get('/myClue')
	}

	getMyDistributor() {
		return this.$get('/myDistributor')
	}

	//  推广线索列表-全部
	clueListServer({ date, size, ...args }) {
		let params = {
			...args,
			size: size
		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		// console.log(params)
		return this.$get("/clueListServer", { params }).then(res => {
			// console.log(res)
			return {
				list: res.data || res ,
				pagination: {
					...params,
					size,
					total: res.total || res.length
				}
			};
		});
	}

	// 推广线索领取
	serverGetClue(params) {
		return this.$post("/serverGetClue", params);
	}

	//  线索-广告账户通过率报表
	clueSupplieReport({ date, size, ...args }) {
		let params = {
			...args,
			size: size
		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		// console.log(params)
		return this.$get("/clueSupplieReport", { params })
	}

	//  线索-客服通过率报表
	clueServerReport({ date, size, ...args }) {
		let params = {
			...args,
			size: size
		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		// console.log(params)
		return this.$get("/clueServerReport", { params })
	}

	countTrace(params) {
		return this.$post("/countTrace", params)
	}

	dispatchPersonPlan(params) {
		return this.$post("/batchPersonPlan", params)
	}

	spreadPersonReport({ date, ...args }) {
		let params = {
			...args,
		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		// console.log(params)
		return this.$get("/spreadPersonReport", { params })
	}

	spreadAdvertiserReport({ date, ...args }) {
		let params = {
			...args,
		};
		if (date && date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}
		// console.log(params)
		return this.$get("/spreadAdvertiserReport", { params })
	}

	promotiontracefile = this.$baseUrl + '/Spread/promotiontracefile'
	uploadClueFile = this.$baseUrl + '/Spread/clueFile'
}
export default Spread;
